#include "Value.h"
#include "iniFile.h"
#include <iostream>

using namespace utility::common;
using namespace utility::ini;

int main()
{
	//Value v1(true);
	//Value v2(123);
	//Value v3(1.23);
	//Value v4("hello world");

	//bool b = v1;
	//int i = v2;
	//double f = v3;
	//const string& s = v4;
	//std::cout << b << std::endl;
	//std::cout << i << std::endl;
	//std::cout << f << std::endl;
	//std::cout << s << std::endl;

	//IniFile ini;
	//ini.load("../../example/main.ini");
	////const string& ip = ini.get("server", "ip");
	////int port = ini.get("server", "port");
	////ini.set("server", "timeout", 1000);
	////ini.set("server", "flag", true);

	//const string& ip = ini["server"]["ip"];
	//int port = ini["server"]["port"];

	//ini["server"]["timeout"] = 1000;
	//ini["server"]["flag"] = true;

	//std::cout << "ip = " << ip << std::endl;
	//std::cout << "port = " << port << std::endl;

	//bool b_ip = ini.has("server", "ip");
	//bool b_section = ini.has("server");	
	//
	//ini.show();
	//
	//ini.remove("server", "ip");
	//ini.show();

	//ini.remove("server");

	//std::cout << ini.str() << std::endl;

		// load ini file
	const string& filename = "../../example/main.ini";
	IniFile ini(filename);

	// show the ini file
	ini.show();

	// dump the ini file
	ini.save("./main2.ini");

	// get value
	const string& name = ini["profile"]["name"];
	std::cout << "ini[\"profile\"][\"name\"] = " << name << std::endl;

	// get value
	int age = ini.get("profile", "age");
	std::cout << "ini[\"profile\"][\"age\"] = " << age << std::endl;

	// set value
	ini["profile"]["age"] = 31;

	// set value
	ini.set("profile", "age", 32);

	age = ini["profile"]["age"];
	std::cout << "int[\"profile\"][\"age\"] = " << age << std::endl;

	// if the server section is exist
	if (ini.has("server"))
	{
		std::cout << "ini[\"server\"] is exist" << std::endl;
	}

	// if the server section and ip key is exist
	if (ini.has("server", "ip"))
	{
		std::cout << "ini[\"server\"][\"ip\"] is exist" << std::endl;
	}

	// remove the key ip in server section
	ini.remove("server", "ip");

	// remove the sever section
	ini.remove("server");

	// clear the ini file
	ini.clear();



	return 0;	
}